package demo.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 创建线程方式三
 * Callable、FutureTask
 * @author small瑞
 */
public class ThreadTest03 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<String> callable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                int sum = 1 ;
                for(int i = 1 ; i < 6 ; i++){
                    sum*=i;
                }
                return "线程02的输出:"+sum;
            }
        } ;
        FutureTask<String> futureTask = new FutureTask<>(callable);

        Thread thread = new Thread(futureTask,"无敌杀神");
        thread.start();
        System.out.println(futureTask.get());
    }
}
